/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include <iostream>
#include "gtest/gtest.h"
#include "named_stub.h"
#include "gmock/gmock.h"
#include "gmock/gmock-actions.h"
#include "ObjectStorageRestoreJob.h"
#include "Backup.h"
#include "ScanMgr.h"
#include "ErrorCode.h"
#include "mockcpp/mockcpp.hpp"

using namespace std;
using namespace OBSPlugin;
using namespace Module;
using namespace FS_Backup;
namespace {
    const uint32_t NUM3 = 3;
    const uint32_t NUM80 = 80;
    const uint32_t NUM200 = 200;
}

class TestScanner : public Scanner {
public:
    explicit TestScanner(ScanConfig scanConfig);
    ~TestScanner() {};

    SCANNER_STATUS Start() override;
    SCANNER_STATUS Abort()override;
    SCANNER_STATUS Destroy() override;
    SCANNER_STATUS Enqueue(
        const std::string &directory, const std::string &prefix = "", uint8_t filterFlag = 0) override;
    SCANNER_STATUS EnqueueV2(const std::string& directory) override;
    SCANNER_STATUS GetStatus() override;
    ScanStatistics GetStatistics() override;
    ErrRecorder QueryFailure() override;
    bool firstCall {true};
protected:
    ScanConfig m_config;
};

TestScanner::TestScanner(ScanConfig scanConfig) : Scanner(scanConfig) {}
SCANNER_STATUS TestScanner::Start()
{
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS TestScanner::Abort()
{
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS TestScanner::Destroy()
{
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS TestScanner::Enqueue(const std::string& directory, const std::string& prefix, uint8_t filterFlag)
{
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS TestScanner::EnqueueV2(const std::string& directory)
{
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS TestScanner::GetStatus()
{
    if (firstCall) {
        firstCall = false;
        return SCANNER_STATUS::SCAN_IN_PROGRESS;
    }
    return SCANNER_STATUS::COMPLETED;
}
ScanStatistics TestScanner::GetStatistics()
{
    ScanStatistics scanStatistics;
    return scanStatistics;
}

ErrRecorder TestScanner::QueryFailure() {
    ErrRecorder errRecorder {};
    return errRecorder;
}

namespace FS_Backup {
class TestBackup : public Backup {
public:
    explicit TestBackup(BackupParams backupParams);
    TestBackup(std::string source, std::string destination);
    ~TestBackup() override;

    BackupRetCode Start() override;
    BackupRetCode Abort() override;
    BackupRetCode Destroy() override;
    BackupRetCode Enqueue(std::string contrlFile) override;
    BackupPhaseStatus GetStatus() override;
    BackupStats GetStats() override;
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
    int callCount {0};
};

TestBackup::TestBackup(BackupParams backupParams) :  Backup(backupParams) {};
TestBackup::~TestBackup() {};

BackupRetCode TestBackup::Start()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode TestBackup::Abort()
{
    return BackupRetCode::FAILED;
}
BackupRetCode TestBackup::Destroy()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode TestBackup::Enqueue(std::string contrlFile)
{
    return BackupRetCode::SUCCESS;
}
BackupPhaseStatus TestBackup::GetStatus()
{
    if (callCount == 0) {
        callCount++;
        return BackupPhaseStatus::INPROGRESS;
    } else if (callCount == 1) {
        callCount++;
        return BackupPhaseStatus::ABORT_INPROGRESS;
    }
    return BackupPhaseStatus::COMPLETED;
}
BackupStats TestBackup::GetStats()
{
    BackupStats backupStats;
    return backupStats;
}
std::unordered_set<FailedRecordItem, FailedRecordItemHash> TestBackup::GetFailedDetails()
{
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
    return ret;
}
}

static std::unique_ptr<Scanner> CreateScanInstStubSucc(ScanConfig scanConfig)
{
    ScanConfig xx;
    return std::make_unique<TestScanner>(xx);
}

static std::unique_ptr<FS_Backup::Backup> CreateBackupInstStubSucc(BackupParams backupParams)
{
    BackupParams xx;
    return std::make_unique<FS_Backup::TestBackup>(xx);
}

static std::unique_ptr<FS_Backup::Backup> CreateBackupInstStubFail(BackupParams backupParams)
{
    return nullptr;
}

class ObjectStorageRestoreJobTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase();
    static void TearDownTestCase();
    AppProtect::RestoreJob RestoreJobInfoSetUp();
    void RestoreCopyInfoSetup(Copy& copy);
    LLTSTUB::Stub stub;
    static void ReportProgressSucc();
    ObjectStorageRestoreJob m_ins;
};

static void ReturnVoidStub()
{
    return;
}

static void ReportJobCompleteStatusStub(ObjectStorageRestoreJob *obj)
{
    return;
}

static void ReportJobProgressStub(ObjectStorageRestoreJob *obj)
{
    return;
}

static int StubFunctionSucc()
{
    return 0;
}

void ObjectStorageRestoreJobTest::SetUp()
{
    MOCKER_CPP(&sleep)
            .stubs()
            .will(invoke(StubFunctionSucc));
}

void ObjectStorageRestoreJobTest::TearDown()
{
    GlobalMockObject::verify(); // 校验mock规范并清除mock规范
}

void ObjectStorageRestoreJobTest::SetUpTestCase()
{
}

void ObjectStorageRestoreJobTest::TearDownTestCase()
{
}

void ObjectStorageRestoreJobTest::ReportProgressSucc()
{
    return;
}
void ObjectStorageRestoreJobTest::RestoreCopyInfoSetup(Copy& copy) {
    HostAddress hostaddress;
    hostaddress.ip="10.28.12.144";
    Json::Value jsonValue;
    jsonValue["esn"] = "esn1";
    Json::FastWriter jsonWriter;
    std::string extendEsn = jsonWriter.write(jsonValue);
    string path = "/MetaFS/cache";
    StorageRepository cacheRepo;
    cacheRepo.repositoryType = RepositoryDataType::CACHE_REPOSITORY;
    cacheRepo.path.push_back(path);
    cacheRepo.extendInfo = extendEsn;

    StorageRepository dataRepo;
    dataRepo.repositoryType = RepositoryDataType::DATA_REPOSITORY;
    dataRepo.path.push_back(path);
    dataRepo.remoteHost.push_back(hostaddress);
    dataRepo.extendInfo = extendEsn;

    StorageRepository metaRepo;
    metaRepo.repositoryType = RepositoryDataType::META_REPOSITORY;
    metaRepo.path.push_back(path);
    metaRepo.remoteHost.push_back(hostaddress);
    metaRepo.extendInfo = extendEsn;
    BackupObjectInfosInCopy m_backupObjectCopyInfo;
    BackupObjectInfo tmpObjectInfos;
    tmpObjectInfos.esn = "esn1";
    m_backupObjectCopyInfo.objectInfos.emplace_back(tmpObjectInfos);
    std::string extendInfo;
    Module::JsonHelper::StructToJsonString(m_backupObjectCopyInfo, extendInfo);
    copy.id = "12344";
    copy.__set_extendInfo(extendInfo); 
    copy.repositories.push_back(cacheRepo);
    copy.repositories.push_back(dataRepo);
    copy.repositories.push_back(metaRepo);
    copy.protectObject.subType = "0";
}
AppProtect::RestoreJob ObjectStorageRestoreJobTest::RestoreJobInfoSetUp()
{
    AppProtect::RestoreJob restoreJob;
    restoreJob.requestId = "123456789";
    restoreJob.jobId = "111111";

    string authExtendInfo;
    ObjectStorageAuthExtendInfo obsAuthInfo;
    obsAuthInfo.ak = "testak";
    obsAuthInfo.sk = "testsk";
    obsAuthInfo.endPoint = "10.12.23.56";
    Module::JsonHelper::StructToJsonString(obsAuthInfo, authExtendInfo);
    restoreJob.targetObject.extendInfo = authExtendInfo;

    string extendInfoStr;
    ObjectStorageDataLayOutExtend ObsDataLayExtent;
    Module::JsonHelper::StructToJsonString(ObsDataLayExtent, extendInfoStr);
    restoreJob.targetObject.extendInfo = extendInfoStr;
    Copy copy;
    RestoreCopyInfoSetup(copy);
   
    restoreJob.copies.push_back(copy);
    restoreJob.copies.push_back(copy);

    std::vector<ApplicationResource>  restoreSubObjects;
    ApplicationResource applicationResource;
    applicationResource.name = "/1.txt";
    restoreJob.restoreSubObjects.push_back(applicationResource);
    applicationResource.name = "/A_dir/";
    restoreJob.restoreSubObjects.push_back(applicationResource);

    ResourceFilter resourceFilter;
    restoreJob.jobParam.filters.push_back(resourceFilter);
    restoreJob.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;

    return restoreJob;
}

/*
 * 用例名称:获取恢复job信息
 * 前置条件：无
 * check点：获取恢复job信息
 */
TEST_F(ObjectStorageRestoreJobTest, GetRestoreJobInfo)
{
    EXPECT_EQ(m_ins.GetRestoreJobInfo(), false);
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::InitJobInfo)
            .stubs()
            .will(returnValue(true));
    int ret = m_ins.GetRestoreJobInfo();
    EXPECT_EQ(m_ins.GetRestoreJobInfo(), true);
}

/*
 * 用例名称:前处理
 * 前置条件：无
 * check点：前处理
 */
TEST_F(ObjectStorageRestoreJobTest, PrerequisiteJob)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::GetRestoreJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrerequisiteJobInner)
            .stubs()
            .will(returnValue(Module::SUCCESS));
    int ret = m_ins.PrerequisiteJob();
    EXPECT_EQ(ret, Module::FAILED);

    ret = m_ins.PrerequisiteJob();
    EXPECT_EQ(ret, Module::SUCCESS);
}

/*
 * 用例名称:HoldScanner
 * 前置条件：无
 * check点：HoldScanner
 */
TEST_F(ObjectStorageRestoreJobTest, HoldScanner)
{
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ScanMgr::HoldRunningTask)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(false))
            .then(returnValue(true));

    EXPECT_NO_THROW(m_ins.HoldScanner());
    EXPECT_NO_THROW(m_ins.HoldScanner());
    EXPECT_NO_THROW(m_ins.HoldScanner());
    EXPECT_NO_THROW(m_ins.HoldScanner());
}

/*
 * 用例名称:ReleaseScanner
 * 前置条件：无
 * check点：ReleaseScanner
 */
TEST_F(ObjectStorageRestoreJobTest, ReleaseScanner)
{
    MOCKER_CPP(&ScanMgr::ReleaseRunningTask)
            .stubs()
            .will(returnValue(true));

    EXPECT_NO_THROW(m_ins.ReleaseScanner());
}

/*
 * 用例名称:检查生成子任务
 * 前置条件：无
 * check点：检查生成子任务
 */
TEST_F(ObjectStorageRestoreJobTest, GenerateSubJob)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageRestoreJob::GetRestoreJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::KeepPluginAlive)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ReleaseScanner)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportJobCompleteStatus)
            .stubs()
            .will(invoke(ReportJobCompleteStatusStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::HoldScanner)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(true))
            .then(returnValue(false));
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubJobTaskToCreateRestoreSubJob)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));

    EXPECT_EQ(m_ins.GenerateSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.GenerateSubJob(), Module::SUCCESS);
    EXPECT_EQ(m_ins.GenerateSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.GenerateSubJob(), Module::SUCCESS);
}

void InitSubJobInfoStub(ObjectStorageBackupSubJob& subJobInfo)
{
    subJobInfo.dataCachePath = "/home";
    subJobInfo.metaFilePath = "/home";
    subJobInfo.dcacheAndFcachePath = "/home";
    subJobInfo.copyId = "111111111111";
    subJobInfo.m_ControlFile = "test_control.txt";
    subJobInfo.m_SubTaskType = SUBJOB_TYPE_CREATE_SUBJOB_PHASE;
}
/*
 * 用例名称:执行子任务
 * 前置条件：无
 * check点：执行子任务
 */
TEST_F(ObjectStorageRestoreJobTest, ExecuteSubJob)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageRestoreJob::GetRestoreJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::GetExecuteSubJobType)
            .stubs()
            .will(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS));
    MOCKER_CPP(&Module::JsonHelper::JsonStringToStruct<ObjectStorageBackupSubJob>)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&JobService::ReportJobDetails).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ExecutePrefixScanSubJob).stubs().will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageRestoreJob::ExecuteRestoreSubJobInner).stubs().will(returnValue(Module::SUCCESS));
    ObjectStorageBackupSubJob subJobInfo;
    string subJobInfoStr;
    SubJob subJob;
    m_ins.m_dataSize = NUM3;
    InitSubJobInfoStub(subJobInfo);
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::SUCCESS);
}

TEST_F(ObjectStorageRestoreJobTest, ExecuteSubJob1)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageRestoreJob::GetRestoreJobInfo).stubs().will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::GetExecuteSubJobType).stubs().will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&JobService::ReportJobDetails).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ExecuteRestoreSubJobInner).stubs().will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageRestoreJob::ExecutePrefixScanSubJob).stubs()
            .will(returnValue(Module::SUCCESS));

    ObjectStorageBackupSubJob subJobInfo;
    subJobInfo.dataCachePath = "/home";
    subJobInfo.metaFilePath = "/home";
    subJobInfo.dcacheAndFcachePath = "/home";
    subJobInfo.copyId = "111111111111";
    subJobInfo.m_ControlFile = "test_control.txt";
    string subJobInfoStr;
    SubJob subJob;

    subJobInfo.m_SubTaskType = SUBJOB_TYPE_CREATE_SUBJOB_PHASE;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::SUCCESS);
    subJobInfo.m_SubTaskType = SUBJOB_TYPE_TEARDOWN_PHASE;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::SUCCESS);
    subJobInfo.m_SubTaskType = SUBJOB_TYPE_PREFIX_SCAN_PHASE;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.ExecuteSubJob(), Module::SUCCESS);
}

/*
 * 用例名称:检查后置任务流程
 * 前置条件：无
 * check点：检查后置任务流程顺利运行
 */
TEST_F(ObjectStorageRestoreJobTest, PostJob)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::GetRestoreJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::PostJobInner)
            .stubs()
            .will(returnValue(Module::SUCCESS));

    EXPECT_EQ(m_ins.PostJob(), Module::FAILED);
    EXPECT_EQ(m_ins.PostJob(), Module::SUCCESS);
}

/*
 * 用例名称:检查前置任务内部流程
 * 前置条件：无
 * check点：检查前置任务内部流程
 */
TEST_F(ObjectStorageRestoreJobTest, PrerequisiteJobInner)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintJobInfo)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::CreateDirectory)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::CreateSharedResources)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::SetupMetaFsForRestoreJob)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));

    EXPECT_EQ(m_ins.PrerequisiteJobInner(), Module::FAILED);
    EXPECT_EQ(m_ins.PrerequisiteJobInner(), Module::FAILED);
    EXPECT_EQ(m_ins.PrerequisiteJobInner(), Module::FAILED);
    EXPECT_EQ(m_ins.PrerequisiteJobInner(), Module::SUCCESS);
}

TEST_F(ObjectStorageRestoreJobTest, PrerequisiteJobInner1)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::CheckCreateBucketExist)
            .stubs()
            .will(returnValue(Module::FAILED));


    EXPECT_EQ(m_ins.PrerequisiteJobInner(), Module::FAILED);
}

/*
 * 用例名称:上报任务完成
 * 前置条件：无
 * check点：上报任务完成
 */
TEST_F(ObjectStorageRestoreJobTest, ReportJobCompleteStatus)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    ObjectStorageNativeScanStatistics scanStatistics;
    SubJobStatus::type jobStatus = SubJobStatus::COMPLETED;
    std::string jobLogLabel = "1";
    int jobProgress = 0;
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportScannerCompleteStatus)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    EXPECT_NO_THROW(m_ins.ReportJobCompleteStatus(jobStatus, jobLogLabel, jobProgress));
    jobStatus = SubJobStatus::RUNNING;
    scanStatistics.m_scanStatus = (int)SCANNER_STATUS::PROTECTED_SERVER_NOT_REACHABLE;
    EXPECT_NO_THROW(m_ins.ReportJobCompleteStatus(jobStatus, jobLogLabel, jobProgress));
    scanStatistics.m_scanStatus = (int)SCANNER_STATUS::SECONDARY_SERVER_NOT_REACHABLE;
    EXPECT_NO_THROW(m_ins.ReportJobCompleteStatus(jobStatus, jobLogLabel, jobProgress));
}

/*
 * 用例名称:检查前置任务内部流程
 * 前置条件：无
 * check点：检查前置任务内部流程
 */
TEST_F(ObjectStorageRestoreJobTest, CreateSubJobInner)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ClearGenerateSubJobEnv)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintJobInfo)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::MonitorScanner)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::InitJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::InitPathForRestore)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::UnzipDcachefiles)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::StartScanner)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateScanStatsResourceWithLock)
        .stubs()
        .will(returnValue(true));
    ObjectStorageBackupSubJob restoreSubJob;
    EXPECT_EQ(m_ins.CreateSubJobInner(restoreSubJob), Module::FAILED);
    PrefixInfo tmpPreInfo1;
    PrefixInfo tmpPreInfo2;
    restoreSubJob.prefixInfo.emplace_back(tmpPreInfo1);
    restoreSubJob.prefixInfo.emplace_back(tmpPreInfo2);
    EXPECT_EQ(m_ins.CreateSubJobInner(restoreSubJob), Module::FAILED);
    EXPECT_EQ(m_ins.CreateSubJobInner(restoreSubJob), Module::FAILED);
    EXPECT_EQ(m_ins.CreateSubJobInner(restoreSubJob), Module::FAILED);
}

/*
 * 用例名称:清除子任务env
 * 前置条件：无
 * check点：清除子任务env
 */
TEST_F(ObjectStorageRestoreJobTest, ClearGenerateSubJobEnv)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    EXPECT_NO_THROW(m_ins.ClearGenerateSubJobEnv());
}

/*
 * 用例名称:获取恢复类型
 * 前置条件：无
 * check点：获取恢复类型
 */
TEST_F(ObjectStorageRestoreJobTest, GetRestoreType)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    jobInfo.jobParam.restoreType = RestoreJobType::FINE_GRAINED_RESTORE;
    m_ins.m_restoreJobPtr = std::make_shared<AppProtect::RestoreJob>(jobInfo);

    EXPECT_NO_THROW(m_ins.GetRestoreType());
}

/*
 * 用例名称:获取恢复类型
 * 前置条件：无
 * check点：获取恢复类型
 */
TEST_F(ObjectStorageRestoreJobTest, ReportJobProgress)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));

    SubJobStatus::type jobStatus = SubJobStatus::COMPLETED;
    std::string jobLogLabel = "1";
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
    jobStatus = SubJobStatus::RUNNING;
    m_ins.m_backupStatus = BackupPhaseStatus::FAILED_NOACCESS;
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
    m_ins.m_backupStatus = BackupPhaseStatus::FAILED_NOSPACE;
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
    m_ins.m_backupStatus = BackupPhaseStatus::FAILED_PROT_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
    m_ins.m_backupStatus = BackupPhaseStatus::FAILED_SEC_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
    m_ins.m_backupStatus = BackupPhaseStatus::INPROGRESS;
    EXPECT_NO_THROW(m_ins.ReportJobProgress(jobStatus, jobLogLabel));
}

/*
 * 用例名称:更新恢复开始时间
 * 前置条件：无
 * check点：更新恢复开始时间
 */
TEST_F(ObjectStorageRestoreJobTest, RetryUpdateBackupStartTime)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::UpdateBackupStartTimeInSharedResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    ObjectStorageBackupSubJob restoreSubJob;

    EXPECT_EQ(m_ins.RetryUpdateBackupStartTime(restoreSubJob), true);
    EXPECT_EQ(m_ins.RetryUpdateBackupStartTime(restoreSubJob), true);
}

/*
 * 用例名称:运行子任务
 * 前置条件：无
 * check点：运行子任务
 */
TEST_F(ObjectStorageRestoreJobTest, ExecuteRestoreSubJobInner)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportJobProgress).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&NodeLevelTaskInfo::Insert).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&NodeLevelTaskInfo::DecrSubTasksCount).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&NodeLevelTaskInfo::IncrSubTasksCount).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::DestroyBackup).stubs().will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintJobInfo).stubs().will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::MonitorRestore).stubs().will(returnValue(NUM3));
    MOCKER_CPP(&ObjectStorageRestoreJob::HandleExecuteSubJobInner)
            .stubs()
            .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&OBSPlugin::CopyFile)
            .stubs()
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::InitJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::GetSharedResources)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::RetryUpdateBackupStartTime)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::StartRestore)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    ObjectStorageBackupSubJob restoreSubJob;
    EXPECT_EQ(m_ins.ExecuteRestoreSubJobInner(restoreSubJob), Module::SUCCESS);
    EXPECT_EQ(m_ins.ExecuteRestoreSubJobInner(restoreSubJob), Module::SUCCESS);
    EXPECT_EQ(m_ins.ExecuteRestoreSubJobInner(restoreSubJob), Module::SUCCESS);
    EXPECT_EQ(m_ins.ExecuteRestoreSubJobInner(restoreSubJob), Module::SUCCESS);
    EXPECT_EQ(m_ins.ExecuteRestoreSubJobInner(restoreSubJob), Module::SUCCESS);
}

/*
 * 用例名称:处理运行子任务
 * 前置条件：无
 * check点：处理运行子任务
 */
TEST_F(ObjectStorageRestoreJobTest, HandleExecuteSubJobInner)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    BackupStats backupStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportJobProgress)
            .stubs()
            .will(invoke(ReturnVoidStub));

    EXPECT_EQ(m_ins.HandleExecuteSubJobInner(backupStatistics, jobStatus, jobLogLabel), Module::SUCCESS);
}

/*
 * 用例名称:创建子任务
 * 前置条件：无
 * check点：创建子任务
 */
TEST_F(ObjectStorageRestoreJobTest, ExecuteCreateSubJobInner)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::ReleaseScanner)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::HoldScanner)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubJobInner)
            .stubs()
            .will(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageRestoreJob::ClearGenerateSubJobEnv)
            .stubs()
            .will(invoke(ReturnVoidStub));
    ObjectStorageBackupSubJob restoreSubJob;
    EXPECT_EQ(m_ins.ExecutePrefixScanSubJob(restoreSubJob), Module::SUCCESS);
}

/*
 * 用例名称:删除文件夹
 * 前置条件：无
 * check点：删除文件夹
 */
TEST_F(ObjectStorageRestoreJobTest, RemoveCacheDirectories)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&OBSPlugin::Remove)
            .stubs()
            .will(returnValue(true));

    EXPECT_NO_THROW(m_ins.RemoveCacheDirectories());
}

/*
 * 用例名称:统计job信息
 * 前置条件：无
 * check点：统计job信息
 */
TEST_F(ObjectStorageRestoreJobTest, CalculateJobStats)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&OBSPlugin::GetFileListInDirectory)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::WriteBackupStatsToFile)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::ReadBackupStatsFromFile)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&OBSPlugin::RemoveFile)
            .stubs()
            .will(returnValue(true));

    EXPECT_EQ(m_ins.CalculateJobStats(), false);
    EXPECT_EQ(m_ins.CalculateJobStats(), true);
}

/*
 * 用例名称:后置任务
 * 前置条件：无
 * check点：后置任务
 */
TEST_F(ObjectStorageRestoreJobTest, PostJobInner)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::InitJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintJobInfo)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::MergeBackupFailureRecords)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageCommonService::GetSharedResources)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::CalculateJobStats)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::DeleteSharedResources)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::ReadBackupStatsFromFile)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::RemoveCacheDirectories)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintBackupCopyInfo)
            .stubs()
            .will(invoke(ReportJobCompleteStatusStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportBackupCompletionStatus)
            .stubs()
            .will(returnValue(true));

    EXPECT_EQ(m_ins.PostJobInner(), Module::FAILED);
    EXPECT_EQ(m_ins.PostJobInner(), Module::FAILED);
    EXPECT_EQ(m_ins.PostJobInner(), Module::SUCCESS);
}

/*
 * 用例名称:生成子任务列表
 * 前置条件：无
 * check点：生成子任务列表
 */
TEST_F(ObjectStorageRestoreJobTest, GenerateSubJobList)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    std::vector<SubJob> subJobList;
    std::vector<std::string> ctrlFileList;
    const std::string srcCtrlFileFullPath;
    const std::string dstCtrlFileFullPath;

    MOCKER_CPP(&ObjectStorageRestoreJob::InitSubJobInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    PrefixInfo prefixInfo;
    EXPECT_EQ(m_ins.GenerateSubJobList(prefixInfo, subJobList, ctrlFileList, srcCtrlFileFullPath, dstCtrlFileFullPath), false);
    EXPECT_EQ(m_ins.GenerateSubJobList(prefixInfo, subJobList, ctrlFileList, srcCtrlFileFullPath, dstCtrlFileFullPath), true);
    m_ins.m_aggregateRestore = true;
    EXPECT_EQ(m_ins.GenerateSubJobList(prefixInfo, subJobList, ctrlFileList, srcCtrlFileFullPath, dstCtrlFileFullPath), true);
}

/*
 * 用例名称:从控制文件生成子任务列表
 * 前置条件：无
 * check点：从控制文件生成子任务列表
 */
TEST_F(ObjectStorageRestoreJobTest, CreateSubTasksFromCtrlFile)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    std::string srcDir;
    std::string dstDir;
    uint32_t subTaskType;
    bool isFinal = false;

    MOCKER_CPP(&ObjectStorageCommonService::checkFilePathAndGetSrcFileList)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::CheckAndRetryCreateSubTask)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    PrefixInfo prefixInfo;
    EXPECT_EQ(m_ins.CreateSubTasksFromCtrlFile(prefixInfo, srcDir, dstDir, subTaskType, isFinal), false);
    EXPECT_EQ(m_ins.CreateSubTasksFromCtrlFile(prefixInfo, srcDir, dstDir, subTaskType, isFinal), false);
    EXPECT_EQ(m_ins.CreateSubTasksFromCtrlFile(prefixInfo, srcDir, dstDir, subTaskType, isFinal), true);
}

/*
 * 用例名称:更新解析开始时间
 * 前置条件：无
 * check点：更新解析开始时间
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateCopyPhaseStartTimeInGenRsc)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_generalInfo.m_backupCopyPhaseStartTime = 1;
    EXPECT_EQ(m_ins.UpdateCopyPhaseStartTimeInGenRsc(), true);
    m_ins.m_generalInfo.m_backupCopyPhaseStartTime = 0;

    MOCKER_CPP(&ObjectStorageCommonService::GetCurrentTimeFromRemoteServer)
            .stubs()
            .will(returnValue((uint64_t)0))
            .then(returnValue((uint64_t)1));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));

    EXPECT_EQ(m_ins.UpdateCopyPhaseStartTimeInGenRsc(), false);
    EXPECT_EQ(m_ins.UpdateCopyPhaseStartTimeInGenRsc(), false);
    m_ins.m_generalInfo.m_backupCopyPhaseStartTime = 0;
    EXPECT_EQ(m_ins.UpdateCopyPhaseStartTimeInGenRsc(), true);
}

/*
 * 用例名称:初始化子任务信息
 * 前置条件：无
 * check点：初始化子任务信息
 */
TEST_F(ObjectStorageRestoreJobTest, InitSubJobInfo)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    SubJob subJob;
    const std::string jobId;
    const std::string ctrlFile;
    uint32_t subTaskType;

    MOCKER_CPP(&ObjectStorageCommonService::GetSubJobTypeByFileName)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&Module::JsonHelper::StructToJsonString<ObjectStorageBackupSubJob>)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    PrefixInfo prefixInfo;
    EXPECT_EQ(m_ins.InitSubJobInfo(prefixInfo, subJob, jobId, ctrlFile, subTaskType), false);
    EXPECT_EQ(m_ins.InitSubJobInfo(prefixInfo, subJob, jobId, ctrlFile, subTaskType), true);
}

/*
 * 用例名称:监控扫描
 * 前置条件：无
 * check点：监控扫描
 */
TEST_F(ObjectStorageRestoreJobTest, MonitorScanner)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ScanMgr::GetScanStatus)
            .stubs()
            .will(returnValue(SCANNER_STATUS::INIT))
            .then(returnValue(SCANNER_STATUS::FREE))
            .then(returnValue(SCANNER_STATUS::COMPLETED));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(true))
            .then(returnValue(false));
    MOCKER_CPP(&ScanMgr::AbortScan)
            .stubs()
            .will(returnValue(SCANNER_STATUS::FAILED));
    MOCKER_CPP(&ScanMgr::GetScanStats)
            .stubs()
            .will(ignoreReturnValue());
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubTasksFromCtrlFile)
            .stubs()
            .will(returnValue(false));
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubJobTaskToCreateRestoreSubJob)
            .stubs()
            .will(returnValue(false));
    ObjectStorageNativeScanStatistics scanStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    PrefixInfo prefixInfo;
    EXPECT_NO_THROW(m_ins.MonitorScanner(prefixInfo, jobStatus, jobLogLabel, jobProgress));
}

TEST_F(ObjectStorageRestoreJobTest, MonitorScanner1)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ScanMgr::GetScanStatus)
            .stubs()
            .will(returnValue(SCANNER_STATUS::INIT))
            .then(returnValue(SCANNER_STATUS::FREE))
            .then(returnValue(SCANNER_STATUS::COMPLETED));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(true))
            .then(returnValue(false));
    MOCKER_CPP(&ScanMgr::AbortScan)
            .stubs()
            .will(returnValue(SCANNER_STATUS::FAILED));
    MOCKER_CPP(&ScanMgr::GetScanStats)
            .stubs()
            .will(ignoreReturnValue());
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubTasksFromCtrlFile)
            .stubs()
            .will(returnValue(false));
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubJobTaskToCreateRestoreSubJob)
            .stubs()
            .will(returnValue(true));
    ObjectStorageNativeScanStatistics scanStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    PrefixInfo prefixInfo;
    EXPECT_NO_THROW(m_ins.MonitorScanner(prefixInfo, jobStatus, jobLogLabel, jobProgress));
}

/*
 * 用例名称:上报扫描运行状态
 * 前置条件：无
 * check点：上报扫描运行状态
 */
TEST_F(ObjectStorageRestoreJobTest, ReportScannerRunningStatus)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    ScanStatistics scanStatistics;

    MOCKER_CPP(&OBSPlugin::GetCurrentTimeInSeconds)
            .stubs()
            .will(returnValue(NUM80))
            .then(returnValue(0));
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    scanStatistics.mTotFailedDirs = NUM3;
}

/*
 * 用例名称:上报扫描完成状态
 * 前置条件：无
 * check点：上报扫描完成状态
 */
TEST_F(ObjectStorageRestoreJobTest, ReportScannerCompleteStatus)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    OBSPlugin::ObjectStorageNativeScanStatistics scanStatistics;

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    scanStatistics.m_totFailedFiles = 1;
    EXPECT_EQ(m_ins.ReportScannerCompleteStatus(scanStatistics), true);
    scanStatistics.m_totFailedFiles = 0;
    EXPECT_EQ(m_ins.ReportScannerCompleteStatus(scanStatistics), true);
}

/*
 * 用例名称:填写监控扫描细节
 * 前置条件：无
 * check点：填写监控扫描细节
 */
TEST_F(ObjectStorageRestoreJobTest, FillMonitorScannerVarDetails)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    SCANNER_TASK_STATUS scanTaskStatus;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    m_ins.m_scanStatus = SCANNER_STATUS::COMPLETED;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::FAILED;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::ABORT_IN_PROGRESS;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::ABORTED;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::SCAN_READ_COMPLETED;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::CTRL_DIFF_IN_PROGRESS;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::SECONDARY_SERVER_NOT_REACHABLE;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::PROTECTED_SERVER_NOT_REACHABLE;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
    m_ins.m_scanStatus = SCANNER_STATUS::ERROR_INC_TO_FULL;
    EXPECT_NO_THROW(m_ins.FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress));
}

/*
 * 用例名称:监控恢复
 * 前置条件：无
 * check点：监控恢复
 */
TEST_F(ObjectStorageRestoreJobTest, MonitorRestore)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageRestoreJob::HandleMonitorComplete)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::UpdateBackupStatistics)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::IsAbortJob)
            .stubs()
            .will(returnValue(true));
    LLTSTUB::Stub stub;
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStubSucc);
    ObjectStorageBackupSubJob restoreSubJob;
    m_ins.StartRestore(restoreSubJob);

    BackupStats backupStatistics;
    backupStatistics.backupspeed = NUM3;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    EXPECT_NO_THROW(m_ins.MonitorRestore(backupStatistics, jobStatus, jobLogLabel, jobProgress));
    m_ins.DestroyBackup();
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:监控放弃
 * 前置条件：无
 * check点：监控放弃
 */
TEST_F(ObjectStorageRestoreJobTest, HandleMonitorAbort)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    LLTSTUB::Stub stub;
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStubSucc);
    ObjectStorageBackupSubJob restoreSubJob;
    m_ins.StartRestore(restoreSubJob);
    MOCKER_CPP(&BasicJob::IsAbortJob)
        .stubs()
        .will(returnValue(true));

    EXPECT_NO_THROW(m_ins.HandleMonitorAbort());
    m_ins.DestroyBackup();
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:监控完成
 * 前置条件：无
 * check点：监控完成
 */
TEST_F(ObjectStorageRestoreJobTest, HandleMonitorComplete)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    EXPECT_NO_THROW(m_ins.HandleMonitorComplete(jobStatus, jobLogLabel, jobProgress));
}

/*
 * 用例名称:监控失败
 * 前置条件：无
 * check点：监控失败
 */
TEST_F(ObjectStorageRestoreJobTest, HandleMonitorFailed)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    EXPECT_NO_THROW(m_ins.HandleMonitorFailed(jobStatus, jobLogLabel));
}

/*
 * 用例名称:监控卡主
 * 前置条件：无
 * check点：监控卡主
 */
TEST_F(ObjectStorageRestoreJobTest, HandleMonitorStuck)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageRestoreJob::UpdateBackupStatistics)
        .stubs()
        .will(returnValue(true));

    LLTSTUB::Stub stub;
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStubSucc);
    ObjectStorageBackupSubJob restoreSubJob;
    m_ins.StartRestore(restoreSubJob);

    BackupStats backupStatistics;
    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    int jobProgress;
    EXPECT_NO_THROW(m_ins.HandleMonitorStuck(backupStatistics, jobStatus, jobLogLabel, jobProgress));
    m_ins.DestroyBackup();
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:上报运行状态
 * 前置条件：无
 * check点：上报运行状态
 */
TEST_F(ObjectStorageRestoreJobTest, ReportBackupRunningStatus)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&OBSPlugin::GetFileListInDirectory)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    EXPECT_EQ(m_ins.ReportBackupRunningStatus(), false);
    EXPECT_EQ(m_ins.ReportBackupRunningStatus(), true);
}

/*
 * 用例名称:上报运行完成状态
 * 前置条件：无
 * check点：上报运行完成状态
 */
TEST_F(ObjectStorageRestoreJobTest, ReportBackupCompletionStatus)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    ObjectStorageNativeBackupStats backupStatistics;
    backupStatistics.m_noOfDirFailed = 1;
    EXPECT_EQ(m_ins.ReportBackupCompletionStatus(backupStatistics), true);
    backupStatistics.m_noOfDirFailed = 0;
    EXPECT_EQ(m_ins.ReportBackupCompletionStatus(backupStatistics), true);
}

/*
 * 用例名称:更新子任务开始时间
 * 前置条件：无
 * check点：更新子任务开始时间
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateBackupStartTimeInSharedResource)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&ObjectStorageCommonService::IsUpdateBackupStartTimeRequired)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::LockGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::GetGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::UpdateGeneralInfoForCopyPhase)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::UpdateGeneralInfoForDeletePhase)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UnlockGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(false))
            .then(returnValue(false))
            .then(returnValue(false))
            .then(returnValue(false))
            .then(returnValue(true));
    ObjectStorageBackupSubJob restoreSubJob;

    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), true);
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    restoreSubJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_COPY_PHASE;
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    restoreSubJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_DELETE_PHASE;
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), false);
    EXPECT_EQ(m_ins.UpdateBackupStartTimeInSharedResource(restoreSubJob), true);
}

/*
 * 用例名称:更新拷贝信息
 * 前置条件：无
 * check点：更新拷贝信息
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateGeneralInfoForCopyPhase)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&OBSPlugin::GetCurrentTimeInSeconds)
            .stubs()
            .will(returnValue(0))
            .then(returnValue(1));

    ObjectStorageBackupSubJob restoreSubJob;
    ObjectStorageNativeGeneral generalInfo;
    generalInfo.m_backupCopyPhaseStartTime = 0;
    restoreSubJob.orderNumberForAggregate = 0;
    generalInfo.m_restoreCopyIndex = 1;

    EXPECT_EQ(m_ins.UpdateGeneralInfoForCopyPhase(restoreSubJob, generalInfo), false);
    generalInfo.m_backupCopyPhaseStartTime = 1;
    EXPECT_EQ(m_ins.UpdateGeneralInfoForCopyPhase(restoreSubJob, generalInfo), true);
}

/*
 * 用例名称:更新删除信息
 * 前置条件：无
 * check点：更新删除信息
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateGeneralInfoForDeletePhase)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&OBSPlugin::GetCurrentTimeInSeconds)
            .stubs()
            .will(returnValue(0))
            .then(returnValue(1));

    ObjectStorageBackupSubJob restoreSubJob;
    ObjectStorageNativeGeneral generalInfo;
    generalInfo.m_backupDelPhaseStartTime = 0;
    restoreSubJob.orderNumberForAggregate = 0;
    generalInfo.m_restoreDeleteIndex = 1;

    EXPECT_EQ(m_ins.UpdateGeneralInfoForDeletePhase(restoreSubJob, generalInfo), false);
    generalInfo.m_backupDelPhaseStartTime = 1;
    EXPECT_EQ(m_ins.UpdateGeneralInfoForDeletePhase(restoreSubJob, generalInfo), true);
}

/*
 * 用例名称:初始化任务信息
 * 前置条件：无
 * check点：初始化任务信息
 */
TEST_F(ObjectStorageRestoreJobTest, GetRepoPaths)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_restoreJobPtr = std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_backupObjectCopyInfo.advParms.m_aggregateSwitch = "true";

    EXPECT_EQ(m_ins.GetRepoPaths(), true);
}

TEST_F(ObjectStorageRestoreJobTest, GetRepoPaths1)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_restoreJobPtr = std::make_shared<AppProtect::RestoreJob>(jobInfo);
    MOCKER_CPP(&ObjectStorageRestoreJob::IsAggregate)
            .stubs()
            .will(returnValue(true));

    EXPECT_EQ(m_ins.GetRepoPaths(), true);
}

/*
 * 用例名称:打印任务信息
 * 前置条件：无
 * check点：打印任务信息
 */
TEST_F(ObjectStorageRestoreJobTest, PrintJobInfo)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    EXPECT_EQ(m_ins.PrintJobInfo(), true);
}

/*
 * 用例名称:创建打印文件夹
 * 前置条件：无
 * check点：创建打印文件夹
 */
TEST_F(ObjectStorageRestoreJobTest, SetupMetaFsForRestoreJob)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&OBSPlugin::CreateDirectory)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));

    EXPECT_EQ(m_ins.SetupMetaFsForRestoreJob(), false);
    EXPECT_EQ(m_ins.SetupMetaFsForRestoreJob(), true);
}

/*
 * 用例名称:获取子任务类型
 * 前置条件：无
 * check点：获取子任务类型
 */
TEST_F(ObjectStorageRestoreJobTest, GetExecuteSubJobType)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    ObjectStorageBackupSubJob subJobInfo;
    subJobInfo.dataCachePath = "/home";
    subJobInfo.metaFilePath = "/home";
    subJobInfo.dcacheAndFcachePath = "/home";
    subJobInfo.copyId = "111111111111";
    subJobInfo.m_ControlFile = "test_control.txt";
    string subJobInfoStr;
    SubJob subJob;

    subJobInfo.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_COPY_PHASE;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.GetExecuteSubJobType(), Module::SUCCESS);

    subJobInfo.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_DELETE_PHASE;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.GetExecuteSubJobType(), Module::SUCCESS);

    subJobInfo.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_ANY;
    Module::JsonHelper::StructToJsonString(subJobInfo, subJobInfoStr);
    subJob.jobInfo = subJobInfoStr;
    m_ins.SetSubJob(std::make_shared<SubJob>(subJob));
    EXPECT_EQ(m_ins.GetExecuteSubJobType(), Module::FAILED);
}

TEST_F(ObjectStorageRestoreJobTest, GetExecuteSubJobType1)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&Module::JsonHelper::JsonStringToStruct<ObjectStorageBackupSubJob>)
            .stubs()
            .will(returnValue(false));
    EXPECT_EQ(m_ins.GetExecuteSubJobType(), Module::FAILED);
}

/*
 * 用例名称:监控扫描
 * 前置条件：无
 * check点：监控扫描
 */
TEST_F(ObjectStorageRestoreJobTest, StartScanner)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER(OBSPlugin::GetDeployType)
        .stubs()
        .will(returnValue(std::string("d0")));
    MOCKER_CPP(&ScanMgr::Initiate)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ScanMgr::Enqueue)
            .stubs()
            .will(ignoreReturnValue());
    MOCKER_CPP(&ScanMgr::StartScan)
            .stubs()
            .will(returnValue(SCANNER_STATUS::FAILED))
            .then(returnValue(SCANNER_STATUS::SUCCESS));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateScanStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    EXPECT_EQ(m_ins.StartScanner(), false);
    EXPECT_EQ(m_ins.StartScanner(), false);
    EXPECT_EQ(m_ins.StartScanner(), true);
}

/*
 * 用例名称:创建恢复路径
 * 前置条件：无
 * check点：创建恢复路径
 */
TEST_F(ObjectStorageRestoreJobTest, InitPathForRestore)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

     m_ins.m_aggregateRestore = true;
     m_ins.m_copyIndex = 1;

    MOCKER_CPP(&OBSPlugin::RecurseCreateDirectory)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(true))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true));

    EXPECT_EQ(m_ins.InitPathForRestore(), false);
    EXPECT_EQ(m_ins.InitPathForRestore(), false);
    EXPECT_EQ(m_ins.InitPathForRestore(), false);
    EXPECT_EQ(m_ins.InitPathForRestore(), false);
    EXPECT_EQ(m_ins.InitPathForRestore(), true);
}

/*
 * 用例名称:解压缓存文件
 * 前置条件：无
 * check点：解压缓存文件
 */
TEST_F(ObjectStorageRestoreJobTest, UnzipDcachefiles)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&OBSPlugin::IsFileExist)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    std::string metaPath = "meta";
    EXPECT_FALSE(m_ins.UnzipDcachefiles(metaPath));

    MOCKER_CPP(&Module::runShellCmdWithOutput)
            .stubs()
            .will(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::SUCCESS))
            .then(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS));
    m_ins.m_aggregateRestore = true;
    EXPECT_FALSE(m_ins.UnzipDcachefiles(metaPath));
    EXPECT_FALSE(m_ins.UnzipDcachefiles(metaPath));
    EXPECT_FALSE(m_ins.UnzipDcachefiles(metaPath));
    EXPECT_FALSE(m_ins.UnzipDcachefiles(metaPath));
    EXPECT_TRUE(m_ins.UnzipDcachefiles(metaPath));
}

/*
 * 用例名称:开始扫描
 * 前置条件：无
 * check点：开始扫描
 */
TEST_F(ObjectStorageRestoreJobTest, FillScanConfig)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER(OBSPlugin::GetDeployType)
        .stubs()
        .will(returnValue(std::string("d0")))
        .then(returnValue(std::string("d2")));
    MOCKER_CPP(&ObjectStorageCommonService::FillScanConfigForNative)
            .stubs()
            .will(invoke(ReturnVoidStub));

    ScanConfig scanConfig;
    EXPECT_NO_THROW(m_ins.FillScanConfig(scanConfig));
}

/*
 * 用例名称:开始恢复
 * 前置条件：无
 * check点：开始恢复
 */
TEST_F(ObjectStorageRestoreJobTest, StartRestore)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    LLTSTUB::Stub stub;
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStubSucc);

    ObjectStorageBackupSubJob restoreSubJob;
    EXPECT_EQ(m_ins.StartRestore(restoreSubJob), true);
    m_ins.DestroyBackup();
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

TEST_F(ObjectStorageRestoreJobTest, StartRestore1)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    LLTSTUB::Stub stub;
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStubFail);

    ObjectStorageBackupSubJob restoreSubJob;
    EXPECT_EQ(m_ins.StartRestore(restoreSubJob), false);
    m_ins.DestroyBackup();
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:备份替换规则
 * 前置条件：无
 * check点：备份替换规则
 */
TEST_F(ObjectStorageRestoreJobTest, FillBackupReplacePolicy)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    BackupParams backupParams;
    EXPECT_NO_THROW(m_ins.FillBackupReplacePolicy(backupParams));
    m_ins.m_dataLayoutExt.fileReplaceStrategy = OBSPlugin::REPLACE_POLICY_IGNORE_EXSISTNG_FILES;
    EXPECT_NO_THROW(m_ins.FillBackupReplacePolicy(backupParams));
    m_ins.m_dataLayoutExt.fileReplaceStrategy = OBSPlugin::REPLACE_POLICY_REPLACE_ONLY_IF_OLDER;
    EXPECT_NO_THROW(m_ins.FillBackupReplacePolicy(backupParams));
    m_ins.m_dataLayoutExt.fileReplaceStrategy = "5";
    EXPECT_NO_THROW(m_ins.FillBackupReplacePolicy(backupParams));
}

/*
 * 用例名称:填写一般参数
 * 前置条件：无
 * check点：填写一般参数
 */
TEST_F(ObjectStorageRestoreJobTest, FillBackupCommonParams)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_backupObjectCopyInfo.advParms.m_isBackupAcl = "true";

    BackupParams backupParams;
    EXPECT_NO_THROW(m_ins.FillBackupCommonParams(backupParams));
}

/*
 * 用例名称:填写config参数
 * 前置条件：无
 * check点：填写config参数
 */
TEST_F(ObjectStorageRestoreJobTest, FillBackupConfigPhase)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    BackupParams backupParams;
    ObjectStorageBackupSubJob restoreSubJob;
    restoreSubJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_COPY_PHASE;
    EXPECT_NO_THROW(m_ins.FillBackupConfigPhase(backupParams, restoreSubJob));
    restoreSubJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_DELETE_PHASE;
    EXPECT_NO_THROW(m_ins.FillBackupConfigPhase(backupParams, restoreSubJob));
}

/*
 * 用例名称:填写恢复config参数
 * 前置条件：无
 * check点：填写恢复config参数
 */
TEST_F(ObjectStorageRestoreJobTest, FillRestoreConfig)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_fineGrainedRestore = false;

    BackupParams backupParams;
    ObjectStorageBackupSubJob restoreSubJob;
    restoreSubJob.m_SubTaskType = OBSPlugin::SUBJOB_TYPE_DATACOPY_COPY_PHASE;
    EXPECT_NO_THROW(m_ins.FillRestoreConfig(backupParams, restoreSubJob));
}

/*
 * 用例名称:填写恢复预先参数
 * 前置条件：无
 * check点：填写恢复预先参数
 */
TEST_F(ObjectStorageRestoreJobTest, FillRestoreAdvanceParams)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_authInfo.useHttps = "1";
    m_ins.m_authInfo.proxyEnable = "1";

    BackupParams backupParams;
    ObjectStorageBackupSubJob restoreSubJob;

    EXPECT_NO_THROW(m_ins.FillRestoreAdvanceParams(backupParams, restoreSubJob));
}

/*
 * 用例名称:控制回调函数
 * 前置条件：无
 * check点：控制回调函数
 */
TEST_F(ObjectStorageRestoreJobTest, ScannerCtrlFileCallBack)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    void *usrData;
    string controlFilePath;

    EXPECT_NO_THROW(m_ins.ScannerCtrlFileCallBack(usrData, controlFilePath));
}

/*
 * 用例名称:删除控制回调函数
 * 前置条件：无
 * check点：删除控制回调函数
 */
TEST_F(ObjectStorageRestoreJobTest, RestoreDelCtrlCallBack)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    void *usrData;
    string controlFilePath;

    EXPECT_NO_THROW(m_ins.RestoreDelCtrlCallBack(usrData, controlFilePath));
}

/*
 * 用例名称:更新打印
 * 前置条件：无
 * check点：更新打印
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateBackupStatistics)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&JobService::ReportJobDetails)
            .stubs()
            .will(invoke(ReturnVoidStub));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateBackupSubTaskStatistics)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UnlockBackupStatsResource)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::UpdateBackupStatsResource)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&NodeLevelTaskInfo::CanSendLogReportToPM)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::LockBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::GetBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&OBSPlugin::GetCurrentTimeInSeconds)
            .stubs()
            .will(returnValue(NUM200));

    BackupStats backupStatistics;
    EXPECT_EQ(m_ins.UpdateBackupStatistics(backupStatistics), true);
    EXPECT_EQ(m_ins.UpdateBackupStatistics(backupStatistics), false);
    EXPECT_EQ(m_ins.UpdateBackupStatistics(backupStatistics), false);
    EXPECT_EQ(m_ins.UpdateBackupStatistics(backupStatistics), true);
}

/*
 * 用例名称:打印拷贝信息
 * 前置条件：无
 * check点：打印拷贝信息
 */
TEST_F(ObjectStorageRestoreJobTest, PrintBackupCopyInfo)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_jobResult = AppProtect::JobResult::type::SUCCESS;

    ObjectStorageNativeBackupStats backupStatistics;

    EXPECT_NO_THROW(m_ins.PrintBackupCopyInfo(backupStatistics));
}

TEST_F(ObjectStorageRestoreJobTest, PrintBackupCopyInfo1)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_jobResult = AppProtect::JobResult::type::FAILED;
    ObjectStorageNativeBackupStats backupStatistics;

    EXPECT_NO_THROW(m_ins.PrintBackupCopyInfo(backupStatistics));
}

/*
 * 用例名称:心跳
 * 前置条件：无
 * check点：心跳
 */
TEST_F(ObjectStorageRestoreJobTest, KeepPluginAlive)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.SetJobAborted();

    EXPECT_NO_THROW(m_ins.KeepPluginAlive());
}

/*
 * 用例名称:获取鉴权信息
 * 前置条件：无
 * check点：获取鉴权信息
 */
TEST_F(ObjectStorageRestoreJobTest, GetAuthExtendInfo)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();

    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    m_ins.m_restoreJobPtr = std::make_shared<AppProtect::RestoreJob>(jobInfo);

    MOCKER_CPP(&Module::JsonHelper::JsonStringToStruct<ObjectStorageAuthExtendInfo>)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    EXPECT_EQ(m_ins.GetAuthExtendInfo(), Module::FAILED);
    EXPECT_EQ(m_ins.GetAuthExtendInfo(), Module::SUCCESS);
}

/*
 * 用例名称:获取鉴权信息
 * 前置条件：无
 * check点：获取鉴权信息
 */
TEST_F(ObjectStorageRestoreJobTest, DestroyBackup)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    EXPECT_NO_THROW(m_ins.DestroyBackup());
}

/*
 * 用例名称: CreateSubJobTaskToCreateRestoreSubJobInner
 * 前置条件：无
 * check点：创建子任务
 */
TEST_F(ObjectStorageRestoreJobTest, CreateSubJobTaskToCreateRestoreSubJobInner)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&Module::JsonHelper::StructToJsonString<ObjectStorageBackupSubJob>)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(true))
            .then(returnValue(false));
    MOCKER_CPP(&ObjectStorageCommonService::CreateSubTask, int(ObjectStorageCommonService::*)(const SubJob &))
            .stubs()
            .will(returnValue(Module::RETRY))
            .then((returnValue(Module::FAILED)))
            .then(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageCommonService::SleepForCreateSubTaskError)
            .stubs()
            .will(invoke(ReturnVoidStub));
    std::string extInfo;
    std::string copyId = "123";
    int subTaskPrio = 1;
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJobInner(extInfo, copyId, subTaskPrio), false);
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJobInner(extInfo, copyId, subTaskPrio), true);
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJobInner(extInfo, copyId, subTaskPrio), false);
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJobInner(extInfo, copyId, subTaskPrio), true);
}

/*
 * 用例名称: CreateSubJobTaskToCreateRestoreSubJob
 * 前置条件：无
 * check点：创建子任务
 */
TEST_F(ObjectStorageRestoreJobTest, CreateSubJobTaskToCreateRestoreSubJob)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageRestoreJob::CreateRestoreJobTeardownTask)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::CreateScanJobTeardownTask)
    .stubs()
    .will(returnValue(true));
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJob(), false);
    EXPECT_EQ(m_ins.CreateSubJobTaskToCreateRestoreSubJob(), true);
}

/*
 * 用例名称: CreateRestoreJobTeardownTask
 * 前置条件：无
 * check点：创建子任务
 */
TEST_F(ObjectStorageRestoreJobTest, CreateRestoreJobTeardownTask)
{
    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    jobInfo.jobParam.restoreType = RestoreJobType::NORMAL_RESTORE;
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(jobInfo);
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&Module::JsonHelper::StructToJsonString<ObjectStorageBackupSubJob>)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&BasicJob::IsAbortJob)
            .stubs()
            .will(returnValue(true))
            .then(returnValue(false));
    MOCKER_CPP(&ObjectStorageCommonService::CreateSubTask, int(ObjectStorageCommonService::*)(const SubJob &))
            .stubs()
            .will(returnValue(Module::RETRY))
            .then((returnValue(Module::FAILED)))
            .then(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageCommonService::SleepForCreateSubTaskError)
            .stubs()
            .will(invoke(ReturnVoidStub));

    EXPECT_EQ(m_ins.CreateRestoreJobTeardownTask(), false);
    EXPECT_EQ(m_ins.CreateRestoreJobTeardownTask(), true);
    EXPECT_EQ(m_ins.CreateRestoreJobTeardownTask(), false);
    EXPECT_EQ(m_ins.CreateRestoreJobTeardownTask(), true);
}

/*
 * 用例名称:ExecuteTeardownSubJobInner
 * 前置条件：无
 * check点：执行teardown任务
 */
TEST_F(ObjectStorageRestoreJobTest, ExecuteTeardownSubJobInner)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    MOCKER_CPP(&ObjectStorageCommonService::ReadBackupStatsFromFile)
            .stubs()
            .will(returnValue(true));
    MOCKER_CPP(&ObjectStorageRestoreJob::PrintBackupCopyInfo)
            .stubs()
            .will(invoke(ReportJobCompleteStatusStub));
    MOCKER_CPP(&ObjectStorageRestoreJob::ReportBackupCompletionStatus)
            .stubs()
            .will(returnValue(true));

    EXPECT_EQ(m_ins.ExecuteTeardownSubJobInner(), Module::SUCCESS);
}

/*
 * 用例名称:IsAggregate
 * 前置条件：无
 * check点：判断是否聚合
 */
TEST_F(ObjectStorageRestoreJobTest, IsAggregate)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    EXPECT_EQ(m_ins.IsAggregate(), false);
}

/*
 * 用例名称:HandleMonitorScannerCompletion
 * 前置条件：无
 * check点：扫描完成
 */
TEST_F(ObjectStorageRestoreJobTest, HandleMonitorScannerCompletion)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    std::string scanCtrlFilePath;
    std::string backupCtrlFilePath;
    jobStatus = SubJobStatus::RUNNING;

    MOCKER_CPP(&ObjectStorageRestoreJob::CreateSubTasksFromCtrlFile)
            .stubs()
            .will(returnValue(true));
    PrefixInfo prefixInfo;
    EXPECT_EQ(m_ins.HandleMonitorScannerCompletion(prefixInfo, jobStatus), true);
    jobStatus = SubJobStatus::COMPLETED;
    EXPECT_EQ(m_ins.HandleMonitorScannerCompletion(prefixInfo, jobStatus), true);
}

/*
 * 用例名称:InitJobInfo
 * 前置条件：无
 * check点：初始化任务信息
 */
TEST_F(ObjectStorageRestoreJobTest, InitJobInfo)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    SubJobStatus::type jobStatus;
    std::string jobLogLabel;
    std::string scanCtrlFilePath;
    std::string backupCtrlFilePath;
    jobStatus = SubJobStatus::RUNNING;

    MOCKER_CPP(&ObjectStorageRestoreJob::GetAuthExtendInfo)
            .stubs()
            .will(returnValue(Module::FAILED))
            .then(returnValue(Module::SUCCESS));
    MOCKER_CPP(&ObjectStorageRestoreJob::GetRepoPaths)
            .stubs()
            .will(returnValue(false));

    EXPECT_EQ(m_ins.InitJobInfo(), false);
    EXPECT_EQ(m_ins.InitJobInfo(), false);
}

/*
 * 用例名称:CheckCreateBucketExist
 * 前置条件：无
 * check点：判断桶是否存在
 */
TEST_F(ObjectStorageRestoreJobTest, CheckCreateBucketExist)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    m_ins.m_targetEnvExt.storageType = "2";
    m_ins.m_authInfo.useHttps = "1";
    m_ins.m_authInfo.proxyEnable = "1";
    Module::StorageVerifyInfo verifyInfo;
    Module::HWCloudService HwCloudService(verifyInfo, obs_auth_switch::OBS_OBS_TYPE);
    Module::OBSResult ObsResult;
    ObsResult.result = Module::ResultType::FAILED;
    MOCKER_CPP_VIRTUAL(HwCloudService, &Module::HWCloudService::IsBucketExist)
        .stubs()
        .will(returnValue(ObsResult));
    bool exit;
    EXPECT_EQ(m_ins.CheckCreateBucketExist(exit), Module::FAILED);
}

TEST_F(ObjectStorageRestoreJobTest, ExecuteScanTeardownSubJob)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);
    MOCKER_CPP(&JobService::ReportJobDetails)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER_CPP(&ObjectStorageCommonService::CalcSubScanStats)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));
    MOCKER_CPP(&ObjectStorageCommonService::GetBackupScanStats)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));
    MOCKER(JsonFileTool::WriteToFile<OBSPlugin::ObjectStorageNativeScanStatistics>)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));
    EXPECT_EQ(m_ins.ExecuteScanTeardownSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.ExecuteScanTeardownSubJob(), Module::FAILED);
    EXPECT_EQ(m_ins.ExecuteScanTeardownSubJob(), Module::SUCCESS);
}

/*
 * 用例名称:添加过滤规则
 * 前置条件：无
 * check点：添加过滤规则
 */
TEST_F(ObjectStorageRestoreJobTest, AddFilterRule)
{
    std::shared_ptr<ThriftDataBase> restoreJobInfoPtr =
        std::make_shared<AppProtect::RestoreJob>(ObjectStorageRestoreJobTest::RestoreJobInfoSetUp());
    m_ins.m_jobCommonInfo = std::make_shared<JobCommonInfo>(restoreJobInfoPtr);

    AppProtect::RestoreJob jobInfo = ObjectStorageRestoreJobTest::RestoreJobInfoSetUp();
    ApplicationResource applicationResource1;
    applicationResource1.name = "/hello/";
    ApplicationResource applicationResource2;
    applicationResource2.name = "/hello/test";
    jobInfo.restoreSubObjects.push_back(applicationResource1);
    jobInfo.restoreSubObjects.push_back(applicationResource2);
    m_ins.m_restoreJobPtr = std::make_shared<AppProtect::RestoreJob>(jobInfo);

    ScanConfig scanConfig;
    EXPECT_NO_THROW(m_ins.AddFilterRule(scanConfig));
    m_ins.m_fineGrainedRestore = true;
    EXPECT_NO_THROW(m_ins.AddFilterRule(scanConfig));
}

/*
 * 用例名称:更新扫描状态信息
 * 前置条件：无
 * check点：是否正常进入上报流程
 */
TEST_F(ObjectStorageRestoreJobTest, UpdateScanStatInfo)
{
    MOCKER_CPP(&ObjectStorageCommonService::UpdateScanStatsResourceWithLock)
        .stubs()
        .will(returnValue(false))
        .then(returnValue(true));
    MOCKER_CPP(&JobService::ReportJobDetails)
        .stubs()
        .will(ignoreReturnValue());
    MOCKER_CPP(&ObjectStorageCommonService::CalcSubScanStats)
        .stubs()
        .will(ignoreReturnValue());
    PrefixInfo prefixInfo;
    ObjectStorageNativeScanStatistics scanStatistics;
    EXPECT_EQ(m_ins.UpdateScanStatInfo(prefixInfo, scanStatistics), false);
    EXPECT_EQ(m_ins.UpdateScanStatInfo(prefixInfo, scanStatistics), true);
}